package com.huluobo.high3videoproject.mvp.like.presenter;

import com.huluobo.base.view.BasePresenter;
import com.huluobo.high3videoproject.bean.LikeVideoBeanResult;
import com.huluobo.high3videoproject.mvp.like.model.LikeVideoModel;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class LikeVideoPresenter extends BasePresenter<LikeVideoContract.View> implements LikeVideoContract.Presenter {
    private LikeVideoModel likeVideoModel = new LikeVideoModel();

    @Override
    public void getLikeVideos() {
        likeVideoModel.getLikeVideos().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<LikeVideoBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        compositeDisposable.add(d);
                    }

                    @Override
                    public void onNext(LikeVideoBeanResult likeVideoBeanResult) {
                        if (isAttach()) {
                            getView().onGetLikeVideosSuccess(likeVideoBeanResult);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        if (isAttach()) {
                            getView().onGetLikeVideoFailed(e.getMessage());
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
